<template lang="pug">
  .clearfix
    Modal(
      width="400"
      v-model="isShowChooseBankModal"
      title="请选择发放银行"
      class-name="vertical-center-modal"
    )
      .search-form.mb-10.pr-10
        Form.ivu-row.ivu-form-basic(ref="formData" :model="formData" :rules="rules" :label-width="90")
          FormItem.form-item.ivu-col.pr-20.mb-15(v-for="(item, index) of formItem" :label="item.label" :key="index" :class="item.style" :prop="item.prop")
            template(v-if="item.type === 'select'")
              Select(v-model="formData[item.model]" :placeholder="item.placeholder" clearable filterable)
                Option(
                  v-for="(c_item, c_index) in arrListDown[item.options]"
                  :value="c_item.value"
                  :key="c_index"
                ) {{ c_item.label }}
      .clearfix(slot="footer")
        Button(type="text" @click="cancel") 取消
        Button(type="primary" @click="handleSubmit" :loading="!isCanSubmit") 确定
</template>

<script>
import { FinanceSPayableApi } from '@/api/FinanceSPayable.api.js'
import { Common } from '@/utils/common.js'
export default {
  name: '',

  data () {
    return {
      isShowChooseBankModal: false,
      formData: {
        bankName: ''
      },
      formItem: [
        { type: 'select', label: '发放银行：', placeholder: '请选择发放银行', prop: 'bankName', model: 'bankName', options: 'bankListExport', style: 'ivu-col-span-24' },
      ],
      rules: {
        bankName: [{ required: true, message: '请选择发放银行' }]
      },
      arrListDown: {
        bankListExport: []
      },
      isCanSubmit: true,
      // parentRow: null,
      parentFormData: null,
      parentSelectedId: null,
    }
  },

  watch: {
  },

  mounted () {
  },

  methods: {
    cancel () {
      this.isShowChooseBankModal = false
    },

    show (parentFormData, parentSelectedId) {
      // this.parentRow = row
      this.parentFormData = parentFormData
      this.parentSelectedId = parentSelectedId
      console.log('parentSelectedId: ', parentSelectedId)
      this.isCanSubmit = true
      this.isShowChooseBankModal = true
      this.$refs.formData.resetFields()
    },

    async handleSubmit () {
      var params = {
        SalaryID: this.$route.query.salaryID,
        CompanyID: this.$route.query.companyID,
        SalaryMonth: this.$moment(this.$route.query.salaryMonth).format('YYYY-MM'),
        EmployeeName: this.parentFormData.employeeName,
        IDCardNo: this.parentFormData.iDCardNo,
        BankName: this.formData.bankName,
        Status: this.parentFormData.status,
        SalaryBillIDS: this.parentSelectedId,
        IsEmpty: false,
      }
      console.log('params: ', params)
      this.$refs.formData.validate((valid) => {
        if (valid) {
          console.log('提交表单', params)          
          FinanceSPayableApi.exportGrantData(params).then(res => {
            if (res.data.success) {
              this.isCanSubmit = false
              this.isShowChooseBankModal = false
              // this.$Message.success(res.data.message)
              window.open(baseUrl + res.data.message, '_blank')
            } else {
              this.isCanSubmit = true
              this.$Message.error({
                content: res.data.message,
                duration: 10,
                closable: true
              })
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scope>
</style>
